#include "tester.h"
#include <math.h>






double calcularRes(double res, double error) {
	int len = ceil((res-0.375)/0.5);
	Celda e(SUDESTE, 0, len-1,0);
	Celda s(0, NOROESTE, 0, 0);
	Malla m(len,e,s);
	double resu = m.getResistencia();
	int j = 1;
	int i;
	while((j < len) && (fabs(resu-res) > error)) {
		while((j < len) && (resu > res)){
			i = 0;
			while((resu - res > error) && (i < len)) {
				m.setCelda(i,j);
				resu = m.getResistencia();
				i++;
			}
			j++;
		}
		if(fabs(resu-res) > error ) {
			j--;i--;
			m.resetCelda(i,j);
			resu = m.getResistencia();
			j++;i++;
		}
	}
	return resu;
}


int main() {
	Tester c;
	int n=12;

	double a[n];
	double b[n];
	for(int i=0;i<n;i++) {
		a[i] = (4+(double)i/4);
		b[i] = calcularRes(4+(double)i/4,0.02);
		cout << endl;
	}
	c.nico("PR0.02", a, b, n);

	return 0;
}

